/*************************************************************************
	> File Name: 010.P1049.装箱问题.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  6/29 14:58:52 2021
 ************************************************************************/

#include <iostream>
using namespace std;

int V, n, v[35], dp[20005];

int main() {
    cin >> V >> n;

    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = V; j >= v[i]; j--) {
            dp[j] = max(dp[j], dp[j - v[i]] + v[i]);
        }
    }
    cout << V - dp[V] << endl;

    return 0;
}
